package com.qf.fronted.controller;

import com.qf.fronted.domain.Data;
import com.qf.fronted.service.UserService1;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 用户在注册页面，填写完 “用户名” 之后, 验证用户名是否存在。
 */
@Controller
@CrossOrigin(origins = "*")  //跨域配置
public class ValidateUsernameController {

    private UserService1 userService1;

    private ValidateUsernameController(UserService1 userService1) {
        this.userService1 = userService1;
    }

    @RequestMapping("/validate-username")
    @ResponseBody
    public Data getValidateUsername(String username) {
        boolean isExists = userService1.checkPhoneOrUsername(username);
        Data data = null;
        if(isExists) {  //存在
            data = new Data(-1, "用户名已经存在");
        }else {
            data = new Data(1, "success");
        }
        return data;
    }
}
